package jumpingnotes.restlet;

import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;

public class RestletBook extends Resource {
	private String bookId;

	public RestletBook() {
		super();
	}

	public RestletBook(Context context, Request request, Response response) {
		super(context, request, response);
		init(context, request, response);
	}
	
	@Override
	public void init(Context context, Request request, Response response) {
		super.init(context, request, response);
        this.bookId = (String) request.getAttributes().get("book");
        // Here we add the representation variants exposed
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));
	}

	@Override
	public Representation represent(Variant variant) throws ResourceException {
        Representation result = null;
        if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) {
            result = new StringRepresentation("Book ID \""
                    + this.bookId + "\"");
        }
        return result;
	}
}
